package com.mm;

import com.mm.factory.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.*;
import java.util.Map;

/**
 * @author wdx
 * @date 2021年03月31日 10:10
 */
@SpringBootApplication
public class StudyApplication {
    public static void main(String[] args) throws IOException, InterruptedException {
//        SpringApplication.run(StudyApplication.class, args);
        //工厂模式测试
        /*CoffeeFactory factory = new LatteCoffeeFactory();
        CoffeeFactory factory1 = new AmericanCoffeeFactory();
        CoffeeStore store = new CoffeeStore(factory1);
        Coffee coffee = store.orderCoffee();
        System.out.println(coffee.getName());*/
//        Map<String, String> getenv = System.getenv();
//        System.out.println(getenv);

//        File file = new File("hello.txt");
//        file.createNewFile();
//        String[] a = new String[3];
//        a[0] = "cmd e:";
//        a[1] = "cmd  cd E:\\谷歌\\windows-amd64-filebrowser";
//        a[2] = "cmd  filebrowser -d filebrowser.db users add test1 123456 --perm.admin";
//        System.out.println(exec(a));
       /* String cmd = "cmd /k  \"cd /d E:\\windows-amd64-filebrowser && filebrowser.exe -d filebrowser.db users add " +
                "test9 123456 --perm.admin\"";
        Process process = Runtime.getRuntime().exec(cmd);*/
//        process.waitFor();
//        process.exitValue() ;
        exec("a.bat");
    }

    /**
     * 调用方法
     * @param cmd cmd命令
     * @return
     */
    public static String exec(String cmd) {
        try {
            Process proc = null;
            Runtime rt = Runtime.getRuntime();

                 proc = rt.exec(cmd);
            proc.waitFor();

            InputStream es = proc.getErrorStream();
            String line;
            BufferedReader br;
            br = new BufferedReader(new InputStreamReader(es, "GBK"));
            StringBuffer buffer=new StringBuffer();
            while ((line = br.readLine()) != null) {
                buffer.append(line+"\n");
            }
            return buffer.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

}
